int xpin = 0;                   // x-axis of the accelerometer
int ypin = 1;                   // y-axis
int zpin = 2;                   // z-axis (only on 3-axis models)
int  g1 = 52;
int  g2 = 53;
int  slp = 51;
int xinit,yinit,zinit;
void setup()
{
Serial.begin(9600);

// Provide ground and power by using the analog inputs as normal
// digital pins.  This makes it possible to directly connect the
// breakout board to the Arduino.  If you use the normal 5V and
// GND pins on the Arduino, you can remove these lines.

//Serial.println("enter 0 for write, any other for read");
 //while (1);
 //int inByte = Serial.read();

pinMode(g1, OUTPUT);
pinMode(g2, OUTPUT);
pinMode(slp,OUTPUT);
pinMode(xpin,INPUT);
pinMode(ypin,INPUT);
pinMode(zpin,INPUT);

digitalWrite(g1, HIGH); 
digitalWrite(g2, HIGH);
digitalWrite(slp, HIGH);

xinit=analogRead(xpin);
yinit=analogRead(ypin);
zinit=analogRead(zpin);
 Serial.println("Initial Values");
 Serial.print(xinit);Serial.print(" ");
 Serial.print(yinit);Serial.print(" ");
 Serial.print(zinit);Serial.print(" ");
 Serial.println();
 Serial.println("Measured");
 Serial.flush();
 //while (!Serial.available()){;}
}

#define X_LEFT  390
#define X_RIGHT 250
#define Y_TOP   390
#define Y_BOT   250
void loop()
{

int x,y,z;

x = analogRead(xpin);
y = analogRead(ypin);
z = analogRead(zpin);

if ( (x != xinit) || (y != yinit) || (z != zinit)){
    if ( x > X_LEFT)
       Serial.print("LEFT");
      
    if (x < X_RIGHT)
       Serial.print("RIGHT");
    
    if ( y > Y_TOP )
       Serial.print("TOP");
    
    if (y < Y_BOT )
       Serial.print("BOTTOM");
    Serial.println(); 
    //Serial.print(x);
    //Serial.print(" ");
    //Serial.print(y);
    //Serial.print(" ");
    //Serial.print(z);
    //Serial.println();
    xinit=x; yinit=y; zinit=z;
} else {
  //Serial.println("Skipping");
}
//Serial.flush();
//while (!Serial.available());
// delay(1);
}
